﻿using ProductMonitor.OPCommand;
using ProductMonitor.UserControls;
using ProductMonitor.ViewModel;
using ProductMonitor.Views;

using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProductMonitor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        MainViewModel model = new();
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = model;
        }

        /// <summary>
        /// 显示车间明细
        /// </summary>
        private void ShowDetailUC()
        {
            WorkShopDetailUC workShopDetailUC = new();
            model.MonitorUC = workShopDetailUC;
            //动画效果(从上往下)
            //new Thickness(0,50,0,-50 留出50  下面减少 -50
            //第二个方向，第三个移动时间
            //位移 移动时间
            ThicknessAnimation thicknessAnimation = new(new Thickness(0, 50, 0, -50), new Thickness(0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 400));

            //透明度
            DoubleAnimation doubleAnimation = new(0, 1, new TimeSpan(0, 0, 0, 0, 400));


            //定义属性添加到控件
            Storyboard.SetTarget(thicknessAnimation, workShopDetailUC);
            Storyboard.SetTarget(doubleAnimation, workShopDetailUC);

            //控件下的那个属性
            //方向填充
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));
            //透明度
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity"));

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(thicknessAnimation);
            storyboard.Children.Add(doubleAnimation);
            storyboard.Begin();
        }

        private void GoBackMonitor()
        {
            MonitorUC monitorUC = new();
            model.MonitorUC = monitorUC;
        }


        public Command ShowDetilCommand
        {
            get { return new Command(ShowDetailUC); }
        }
        public Command ShowMainCommand
        {
            get { return new Command(GoBackMonitor); }
        }


        private void BtnMin(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void BtnMax(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Normal)
                this.WindowState = WindowState.Maximized;
            else
                this.WindowState = WindowState.Normal;

        }

        private void BtnClose(object sender, RoutedEventArgs e)
        {
            //  this.Close();//关闭当前界面，代码还跑

            Environment.Exit(0);//直接退出，终止程序
        }

        #region 窗口弹出
        private void SettingShow()
        {
            //窗口父子关系  Owner = this 确定从中间弹出
            SettingsWindow settingsWindow = new() { Owner = this };
            settingsWindow.ShowDialog();


        }

        public Command ShowSettingsCommand
        {
            get { return new Command(SettingShow); }
            #endregion
        }
    }
}